package com.wjw.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author wjw
 * @date 2021年09月26日 20:54
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    // 插入时的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始填充创建时间以及修改时间");
        this.strictInsertFill(metaObject, "createTime", Date.class,
                new Date());
        this.strictInsertFill(metaObject, "updateTime", Date.class,
                new Date());
        this.fillStrategy(metaObject, "version", 1);
        /*this.fillStrategy(metaObject, "createTime", new Date());
        this.fillStrategy(metaObject, "updateTime", new Date());*/
    }

    // 更新时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始填充更改时间");
        this.strictInsertFill(metaObject, "updateTime", Date.class,
                new Date());
        /*this.fillStrategy(metaObject, "updateTime", new Date());*/
    }
}
